package com.ibeeking.found.cms.b.rest.controller.v1;

import com.ibeeking.found.cms.b.rest.service.IPageTemplateBaseService;
import com.ibeeking.found.cms.b.rest.service.IPageTemplateModuleService;
import com.ibeeking.found.cms.service.common.param.PageToTemplateParam;
import com.ibeeking.found.cms.service.common.param.TemplateToPageParam;
import com.ibeeking.found.cms.service.common.query.PageBasePageQuery;
import com.ibeeking.found.cms.service.common.query.PageTemplatePageQuery;
import com.ibeeking.found.cms.service.common.vo.PageBaseVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleAllView;
import com.ibeeking.found.cms.service.common.vo.PageTemplateVO;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.db.annotation.Read;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName PageBaseController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-05-08 16:05
 **/
@RestController
@RequestMapping("/b/pageTemplate/v1")
public class PageTemplateController {

    @Resource
    private IPageTemplateBaseService pageTemplateBaseServiceImpl;

    @Resource
    private IPageTemplateModuleService pageTemplateModuleServiceImpl;


    @Read
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "页面模板分页")
    @PostMapping(value = "/pageTemplateBase/pageTemplateBasePageList")
    public Page<PageBaseVO> pageTemplateBasePageList(@RequestBody PageBasePageQuery query, @LoginUser CurrentUser currentUser) {
        return pageTemplateBaseServiceImpl.pageList(query, currentUser);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "页面设置为模板")
    @PostMapping(value = "/pageTemplateBase/saveToTemplate")
    public Boolean saveToTemplate(@RequestBody @Validated PageToTemplateParam param, @LoginUser CurrentUser user) {
        return pageTemplateBaseServiceImpl.saveToTemplate(param, user);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "")
    @PostMapping(value = "/pageTemplateBase/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return pageTemplateBaseServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "从模板复制")
    @PostMapping(value = "/pageTemplateBase/loadTemplate")
    public Boolean loadTemplateToPage(@RequestBody @Validated TemplateToPageParam param, @LoginUser CurrentUser user) {
        return pageTemplateBaseServiceImpl.loadTemplateToPage(param, user);
    }

    @Read
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看页面模板")
    @PostMapping(value = "/pageTemplateModule/viewPageTemplate/{pageId}")
    public PageModuleAllView viewPageTemplate(@PathVariable("pageId") Long pageId) {
        return pageTemplateModuleServiceImpl.viewByPageId(pageId);
    }

    @Read
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "页面模板分页")
    @PostMapping(value = "/pageTemplateModule/pageTemplateViewPageList")
    public Page<PageModuleAllView> pageTemplateViewPageList(@RequestBody PageTemplatePageQuery query, @LoginUser CurrentUser currentUser) {
        return pageTemplateModuleServiceImpl.pageTemplateViewPageList(query, currentUser);
    }

    @Read
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "页面模板图片分页")
    @PostMapping(value = "/pageTemplateModule/pageTemplatePageList")
    public Page<PageTemplateVO> pageTemplatePageList(@RequestBody PageTemplatePageQuery query, @LoginUser CurrentUser currentUser) {
        return pageTemplateModuleServiceImpl.pageTemplatePageList(query, currentUser);
    }

}